package com.vcaresolution.logistic.service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

//import bsh.util.Util;

import com.vcaresolution.logistic.form.PkgcartingForm;
import com.vcaresolution.logistic.pojo.Pkgcarting;
//import com.vcaresolution.logistic.pojo.Sector;
import com.vcaresolution.logistic.to.PkgcartingTO;
//import com.vcaresolution.util.Utils;

@Service
public class PkgcartingServiceImpl extends BaseService implements PkgcartingService{

	private Pkgcarting populatePkgcartingPojo(PkgcartingForm pkgcartingForm){
		Pkgcarting pkgcarting = new Pkgcarting();
		BeanUtils.copyProperties(pkgcartingForm, pkgcarting);
		
		return pkgcarting;
	}
	
	@Override
	@Transactional
	public void add(PkgcartingForm pkgcartingForm) {
		Pkgcarting pkgcarting = populatePkgcartingPojo(pkgcartingForm);
				
		getDaoFactory().getUtilityDAO().add(pkgcarting);
	}

	@Override
	@Transactional
	public void update(PkgcartingForm pkgcartingForm) {
		Pkgcarting pkgcarting = populatePkgcartingPojo(pkgcartingForm);
				
		getDaoFactory().getUtilityDAO().update(pkgcarting);
	}

	@Override
	@Transactional
	public void delete(PkgcartingForm pkgcartingForm) {
		getDaoFactory().getUtilityDAO().delete(populatePkgcartingPojo(pkgcartingForm));
	}

	@Override
	@Transactional
	public PkgcartingTO findById(Serializable pkgcartingID) {
		Pkgcarting pkgcarting = (Pkgcarting) getDaoFactory().getUtilityDAO().findById(Pkgcarting.class,pkgcartingID);
		
		PkgcartingTO pkgcartingTO = new PkgcartingTO();
		BeanUtils.copyProperties(pkgcarting, pkgcartingTO);
		
		return pkgcartingTO; 
	}

	@Override
	@Transactional
	public List<PkgcartingTO> findByAll() {
		List<Pkgcarting> pkgcartingList = getDaoFactory().getUtilityDAO().findByAll(Pkgcarting.class);
		
		List<PkgcartingTO> pkgcartingFormList = new ArrayList<PkgcartingTO>();
		
		if( pkgcartingList != null && !pkgcartingList.isEmpty() ){
			PkgcartingTO pkgcartingForm = null;
			for(Pkgcarting pkgcarting: pkgcartingList){
				pkgcartingForm = new PkgcartingTO();
				
				BeanUtils.copyProperties(pkgcarting, pkgcartingForm);
//				if(pkgcarting.getCreationadate() != null){
//					jobregisterForm.setCreationDateToString(Utils.convertDateObjectToDDMMYYYY(jobregister.getCreationadate()));
//				}
				pkgcartingFormList.add(pkgcartingForm);
			}
		}	
		return pkgcartingFormList;
	}
}